import ServiceNodeApi from '@/api/ruleNode/serviceNode'
const state = {
  service: {}
}

const mutations = {
  save: (state, { name, value }) => { state[name] = value }
}

const actions = {
  async getService({ commit }) {
    if (state.service.data) {
      return state.service
    } else {
      return await actions.getNewService({ commit })
    }
  },
  async getNewService({ commit }) {
    const { getGacMetaServices } = ServiceNodeApi
    const res = await getGacMetaServices()
    commit('save', { name: 'service', value: res })
    return res
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
